package guet.imagan.progbuilder.impl;

import guet.imagan.progbuilder.DefaultCompiler;
import guet.imagan.progbuilder.Project;
import guet.imagan.progbuilder.annotation.CompileCommand;
import guet.imagan.util.FileUtil;
import guet.imagan.util.ListUtil;

import java.io.File;
import java.util.List;

/**
 * Gcc编译器实现类
 */
@CompileCommand(commpilerName = "GCC编译器",
		sourceFileExtension = {"c", "cpp"},
		targetFileExtension = "exe",
		command = {"gcc", "-finput-charset=utf-8",
				"-fexec-charset=GBK", "{srcFiles}","-o","{targetFile}"}
)
public class GccCompiler extends DefaultCompiler {

	/**
	 * 根据当前Project对象，填充编译器命令行中的占位符
	 *
	 * @param cmd     命令行对象
	 * @param project 当前要编译的项目
	 */
	@Override
	public void populatePlaceHolder(List<String> cmd, Project project) {
		super.populatePlaceHolder(cmd,project);
		String targetFileStr=project.getOutputDir()+File.separator+"target.exe";
		ListUtil.replaceFirst(cmd,"{targetFile}",
				targetFileStr);
	}
}
